package demo6;
import java.util.Calendar;
import java.util.Date;

//显示当前日期，格式为“2019年01月01日 周一 01时01分01秒” 采用两种方式实现,
//不允许使用String.format
//思路一:

public class DisplayDate01 {
    public static void main(String[] args) {
        System.out.println(format(new Date()));
        System.out.println(format(new Date(new
                Date().getTime()+24*60*60*1000)));
        System.out.println(format(new Date(new
                Date().getTime()+48*60*60*1000)));
    }
    public static String ws = " 日一二三四五六";
    public static String format(Date d) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        StringBuilder sb = new StringBuilder();
        sb.append(c.get(Calendar.YEAR));
        sb.append('年');
        if(c.get(Calendar.MONTH)<9) {
            sb.append('0');
        }
        sb.append(c.get(Calendar.MONTH)+1);
        sb.append('月');
        if(c.get(Calendar.DATE)<10) {
            sb.append('0');
        }
        sb.append(c.get(Calendar.DATE));
        sb.append("日 周");
        sb.append(ws.charAt(c.get(Calendar.DAY_OF_WEEK)));
        sb.append(' ');
        if(c.get(Calendar.HOUR_OF_DAY)<10) {
            sb.append('0');
        }
        sb.append(c.get(Calendar.HOUR_OF_DAY));
        sb.append("时");
        if(c.get(Calendar.MINUTE)<10) {
            sb.append('0');
        }
        sb.append(c.get(Calendar.MINUTE));
        sb.append("分");
        if(c.get(Calendar.SECOND)<10) {
            sb.append('0');
        }
        sb.append(c.get(Calendar.SECOND));
        sb.append("秒");
        return sb.toString();
    }
}
